#!/bin/sh
#
# Do delta-indom-stats for all the archives you can find under
# the sun.
#

dirs="$@"
if [ -z "$dirs" ]; then
    echo "Usage: delta-indom-stats-all [path]..."
    exit 1
fi

make delta-indom-stats

find $dirs \( -name "*.meta.*" -o -name "*.meta" \) \
| while read arch
do
    case "$arch"
    in
	*/qa/badarchives/*|*/qa/*.full)
	    ;;
	*)
	    ./delta-indom-stats "$arch" 2>&1
	    ;;
    esac
done >report.full

( sed -n <report.full -e '/Saving/p' -e '/(uncompressed)/{
p
q
}' \
  ; ( grep Total report.full \
      | sort -nr -k4,4 \
    ) \
) \
| sed -e 's/^......................//' \
| awk '
BEGIN		{ big = small = 0 }
NR < 3		{ print; next }
$3 > 1024*1024	{ print; big++; next }
small == 0	{ print "More than 1Mb saving for " big " archives" }
		{ small++ }
END		{ print "And less than 1Mb saving for " small " archives" }'

grep '\(no change\)' report.full \
| wc -l \
| sed -e 's/  *//g' -e 's/.*/No change for & archives./'

echo "See report.full for chapter and verse ..."
